$(document).ready( function() {
	
	var loginBox = '<h3 class="ui-widget-header">Skeleton CBP</h3><center><h2>Login</h2></center>';
	loginBox += '<center><table border=0 cellpadding=3 cellspacing=0 width="100%">';
	loginBox += '<tr><td align=right>Username:</td><td><input type=text id="skel_user" size=20></td></tr>';
	loginBox += '<tr><td align=right>Password:</td><td><input type=password id="skel_pass" size=20></td></tr>';
	loginBox += '<tr><td align=center colspan=2><input type=button id="skel_login" value="Login" onClick="doLogin();"><br><img id="skel_load_anim" style="display:none;" src="ajax-loader.gif"></td></tr>';
	loginBox += '</table></center>';

	$("#mainBox1").html(loginBox);
	$("#skel_login").button();

	$("#errorBox1").click(function() { $(this).hide(); });
	
});

function doLogin() {

	var login = $("#skel_user").val();
	var password = $("#skel_pass").val();

	if (login != '' && password != '') {

		$("#skel_pass").val('').attr("disabled","disabled");
		$("#skel_user").attr("disabled","disabled");
		$("#skel_load_anim").show();
		$("#skel_login").hide();

	
		$.post('index.php', { skel_login: 1, skel_user: login, skel_pass: password }, function (result) {
			if (result == "OK") { 
				showMain();
			} else {
				$("#errorBox1").html('<center><b>Failed to log in.  Please check your username and password.</b><br><i>Wait or Click Here to close</i></center>');
				$("#errorBox1").show();
				$("#skel_load_anim").hide();
				$("#skel_login").show();
				$("#skel_user").attr("disabled","");
				$("#skel_pass").attr("disabled","");
				setTimeout('$("#errorBox1").fadeOut()',4000);
			}
		});
			
		
	}
	
}
